home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / comm.jar.z / comm.jar / content / p3p / p3pSummary.js < prev    next >
Text File  |  2003-11-11  |  7KB  |  193 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is the Platform for Privacy Preferences.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s): Harish Dhurvasula <harishd@netscape.com>
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. const nsIDocShell      = Components.interfaces.nsIDocShell;
  38.  
  39. var gBrowser       = null;
  40. var gDocument      = null;
  41.  
  42. function renderMachineReadable()
  43. {
  44.   var xsltp     = window.arguments[0];
  45.   var source    = window.arguments[1];
  46.   var style     = window.arguments[2];
  47.   var policyuri = window.arguments[3].clone().QueryInterface(nsIURL);
  48.   policyuri.ref = "";
  49.  
  50.   try {
  51.     var docshell  = getSummaryBrowser().docShell.QueryInterface(nsIDocShell);
  52.     
  53.     // For browser security do not allow javascript on the transformed document.
  54.     docshell.allowJavascript = false; 
  55.     
  56.     // Set the policy url on the result document ( fabricated ) where
  57.     // the transformation would result. Also, set the policy uri on the
  58.     // docshell for named anchors to work correctly.
  59.     var resultDocument = getDocument();
  60.     docshell.setCurrentURI(policyuri);
  61.  
  62.     xsltp.reset();
  63.     xsltp.setParameter("", "policyUri", policyuri.spec);
  64.     xsltp.importStylesheet(style);
  65.  
  66.     var result = xsltp.transformToFragment(source, resultDocument);
  67.  
  68.     // XXX Replacing the documentElement makes scrollbars disappear.
  69.     //     See http://bugzilla.mozilla.org/show_bug.cgi?id=205725.
  70.     //while (resultDocument.lastChild} {
  71.     //    resultDocument.removeChild(resultDocument.lastChild);
  72.     //}
  73.     // XXX appendChild of a DocumentFragment should work but doesn't.
  74.     //     See http://bugzilla.mozilla.org/show_bug.cgi?id=209027.
  75.     //resultDocument.appendChild(result);
  76.     transferToDocument(result, resultDocument);
  77.  
  78.     window.title = resultDocument.getElementById("topic").firstChild.nodeValue;
  79.   }
  80.   catch (ex) {
  81.     alertMessage(getBundle().GetStringFromName("InternalError"));
  82.   }
  83. }
  84.  
  85. // XXX Temporary function to workaround disappearing scrollbars
  86. //     and bug in document.appendChild(DocumentFragment).
  87. //     See http://bugzilla.mozilla.org/show_bug.cgi?id=205725
  88. //     and http://bugzilla.mozilla.org/show_bug.cgi?id=209027.
  89. function transferToDocument(aResult, aResultDocument)
  90. {
  91.     var docElement = aResultDocument.documentElement;
  92.     while (aResultDocument.firstChild &&
  93.            aResultDocument.firstChild != docElement) {
  94.         aResultDocument.removeChild(aResultDocument.firstChild);
  95.     }
  96.     while (docElement.lastChild) {
  97.         docElement.removeChild(docElement.lastChild);
  98.     }
  99.     while (aResultDocument.lastChild &&
  100.            aResultDocument.lastChild != docElement) {
  101.         aResultDocument.removeChild(aResultDocument.lastChild);
  102.     }
  103.     var pastDocumentElement = false;
  104.     for (var i = 0; i < aResult.childNodes.length; ++i) {
  105.         var childNode = aResult.childNodes.item(i);
  106.         if (childNode instanceof HTMLElement) {
  107.             while (childNode.firstChild) {
  108.                 aResultDocument.documentElement.appendChild(childNode.removeChild(childNode.firstChild));
  109.             }
  110.             pastDocumentElement = true;
  111.         }
  112.         else {
  113.             if (pastDocumentElement) {
  114.                 aResultDocument.appendChild(childNode);
  115.             }
  116.             else {
  117.                 aResultDocument.insertBefore(childNode, aResultDocument.documentElement);
  118.             }
  119.         }
  120.     }
  121. }
  122.  
  123. function getSummaryBrowser()
  124. {
  125.   if (!gBrowser)
  126.     gBrowser = document.getElementById("content");
  127.   return gBrowser;
  128. }
  129.  
  130. function getDocument()
  131. {
  132.   if (!gDocument)
  133.     gDocument = getSummaryBrowser().contentDocument;
  134.   return gDocument;
  135. }
  136.  
  137. function p3pSummarySavePage()
  138. {
  139.   try
  140.   {
  141.     // make user pick target file
  142.     const kIFilePicker = Components.interfaces.nsIFilePicker;
  143.     var fp = Components.classes["@mozilla.org/filepicker;1"].
  144.       createInstance(kIFilePicker);
  145.  
  146.     fp.init(window, getBundle().GetStringFromName("savePolicy.title"), 
  147.       kIFilePicker.modeSave);
  148.     fp.appendFilters(kIFilePicker.filterAll | kIFilePicker.filterHTML);
  149.     fp.defaultString = window.title;
  150.     fp.defaultExtension = "html";
  151.  
  152.     var rv = fp.show();
  153.  
  154.     // write ``pretty printed'' source to file
  155.     if (rv == kIFilePicker.returnOK || rv == kIFilePicker.returnReplace)
  156.     {
  157.       const kIPersist = Components.interfaces.nsIWebBrowserPersist;
  158.       var persistor = Components.
  159.         classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
  160.         createInstance(kIPersist);
  161.  
  162.         persistor.saveDocument(getDocument(), fp.file, null, "text/html", 
  163.           kIPersist.ENCODE_FLAGS_FORMATTED | 
  164.           kIPersist.ENCODE_FLAGS_ENCODE_BASIC_ENTITIES, 0);
  165.     }
  166.   }
  167.   catch (ex)
  168.   {
  169.     try 
  170.     {
  171.       alertMessage(getBundle().GetStringFromName("saveError"));
  172.     }
  173.     catch (ex)
  174.     {
  175.     }
  176.   }
  177. }
  178.  
  179. /* This method displays additional information, in an alert box, upon request.
  180.  * Note that since javascript is disabled, for security reasons, in the policy viewer
  181.  * we have to capture the specific event, that bubbles up to the chrome, containing
  182.  * the requested message.
  183.  */
  184. function captureContentClick(aEvent)
  185. {
  186.   if (aEvent.target.hasAttribute("message")) {
  187.     alertMessage(aEvent.target.getAttribute("message"));
  188.     return true;
  189.   }
  190.  
  191.   return contentAreaClick(aEvent);
  192. }
  193.